package com.jing.service.impl;

import com.jing.common.core.domain.R;
import com.jing.domain.Vo.ProductAttr;
import com.jing.domain.Vo.ShopAttributeVO;
import com.jing.domain.Vo.ShopSkuStockVO;
import com.jing.domain.po.Product;
import com.jing.domain.po.ProductAttributeValue;
import com.jing.domain.po.ShopAttribute;
import com.jing.mapper.PmsBrandmapper;
import com.jing.service.PmsBrandSservice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author：wp
 * @Package：com.jing.service.impl
 * @Project：jing
 * @name：PmsBrandSserviceimpl
 * @Date：2024/5/29 20:26
 */
@Slf4j
@Service
public class PmsBrandSserviceimpl implements PmsBrandSservice {

    @Autowired
    private PmsBrandmapper pmsBrandmapper;
    @Override
    public List<ProductAttributeValue> list() {
     List<ProductAttributeValue> list= pmsBrandmapper.dgui();
        List<ProductAttributeValue> getlist = getlist ( list, 0 );
        return getlist;
    }

    @Override
    public R<List<Product>> Productlist() {
        List<Product> list=pmsBrandmapper.Productlist();
        return R.ok (list);
    }


    private List<ProductAttributeValue> getlist(List<ProductAttributeValue> list,Integer porductId){
        ArrayList<ProductAttributeValue> objects = new ArrayList<> ();
        for (ProductAttributeValue value : list) {
            if (value.getProductId ().equals ( porductId )){
                List<ProductAttributeValue> getlist = getlist ( list, value.getId () );
                   value.setPos ( getlist );
                   objects.add ( value );
            }

        }
        return objects;
    }

    @Override
    public List<ShopAttributeVO> lisasd(Integer id,Integer type) {
        List<ShopAttribute> list=pmsBrandmapper.lisasd(id,type);
        List<ShopAttributeVO> list1=new ArrayList<> ();
        for (ShopAttribute product : list) {
            String[] split = product.getInputList ().split ( "," );
            ShopAttributeVO shopAttributeVO = new ShopAttributeVO ();
            BeanUtils.copyProperties ( product ,shopAttributeVO);
            ArrayList<ProductAttr> vos = new ArrayList<> ();
            for (String s : split) {
                ProductAttr vo = new ProductAttr ();
                vo.setId ( product.getId () );
                vo.setName ( s );
                vos.add ( vo );
            }
            shopAttributeVO.setInputList ( vos);
            list1.add ( shopAttributeVO );
        }
        return list1;
    }

    @Override
    public List<ShopSkuStockVO> skutype(Integer id) {

        return pmsBrandmapper.skutype(id);
    }


}
